package org.greyhawk.samonitor.domain;

import java.util.Date;

import org.greyhawk.samonitor.service.SiteCrawler;
import org.greyhawk.samonitor.service.SummaryGenerater;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(value="prototype")
public class TextResourcesFactory extends ResourcesFactory {
	
	@Autowired
	private SummaryGenerater summaryGenerater;
	
	@Override
	public SummaryGenerater getSummaryGenerater() {
		return summaryGenerater;
	}
	
	public TextResourcesFactory(){
		super();
	}

	public TextResourcesFactory(SummaryGenerater summaryGenerater){
		this.summaryGenerater = summaryGenerater;
	}
	
	@Override
	public SiteCrawler getSiteCrawler() {
		return null;
	}

	@Override
	public Resources createResources(Site site, ResourcesType type,
			String res) throws Exception {
		Resources resources = new Resources();
		resources.setSite(site);
		resources.setType(type);
		resources.setText(res);
		String summary = summaryGenerater.generateSummary(res.getBytes());
		resources.setSummary(summary);
		resources.setCreateTime(new Date());
		return resources;
	}

}
